package com.cjb.cloudsystem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjb.cloudsystem.entity.TraceabilityData;
import com.cjb.cloudsystem.service.TraceabilityDataService;
import com.cjb.cloudsystem.vo.TraceabilityDataVO;
import com.cjb.common.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Author 1.0.0 2024-03-02
* @Package IntelliJ IDEA
* @Class TraceabilityDataControl
* @Date 2024-03-02
*/
@RestController
@Tag(name="traceabilityData")
@RequestMapping(value = {"traceabilityData"})
@ApiResponses(@ApiResponse(responseCode = "200", description = "接口请求成功"))
@Slf4j
public class TraceabilityDataController {
    /*
    * 注入事物类
    */
    @Autowired
    private TraceabilityDataService traceabilityDataService;

    /**
    *单个保存
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @PostMapping("/save")
    @Operation(summary = "单个保存")

    public Result<Boolean> save(@RequestBody TraceabilityData traceabilityData){
        return Result.success(traceabilityDataService.save(traceabilityData));
    }

    /**
    *批量保存
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @PostMapping("/listSave")
    @Operation(summary = "批量保存")
    public Result <Integer> listSave(@RequestBody List<TraceabilityData> traceabilityData){
        return Result.success(traceabilityDataService.listSave(traceabilityData));
    }

    /**
    *单个查询
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @GetMapping("/queryById")
    @Operation(summary = "单个查询-通过ID")
    public Result<TraceabilityData> queryById(@RequestBody TraceabilityData traceabilityData){
        return Result.success( traceabilityDataService.queryById(traceabilityData));
    }

    /**
    * 分页查询
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @GetMapping("/queryPage")
    @Operation(summary = "分页查询-通过页码")
    public Result<Page<TraceabilityData>> queryPage(@ParameterObject @Valid TraceabilityDataVO traceabilityDataVO){
        Page traceabilityDataPage = new Page<TraceabilityData>(traceabilityDataVO.getPage(),traceabilityDataVO.getLimit());
        return Result.success( traceabilityDataService.queryPage(traceabilityDataPage,traceabilityDataVO));
    }

    /**
    * 批量更新
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @PostMapping("/listUpdate")
    @Operation(summary = "批量更新")
    public Result <String> listUpdate(@RequestBody List<TraceabilityData> traceabilityData){
        traceabilityDataService.listUpdate(traceabilityData);
        return Result.success();
    }


    /**
    * 批量删除
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @PostMapping("/listDelete")
    @Operation(summary = "批量删除")
    public Result <String> listDelete(@RequestBody List<TraceabilityData> traceabilityData){
        traceabilityDataService.listDelete(traceabilityData);
        return Result.success();
    }
    /**
    * 通过id删除
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @PostMapping("/deleteById")
    @Operation(summary = "单个删除-通过ID")
    public Result <String> deleteById(@RequestBody TraceabilityData traceabilityData){
        traceabilityDataService.deleteById(traceabilityData);
        return Result.success();
    }

    /**
    * 返回全部信息
    *
    * @Author 1.0.0 2024-03-02
    * @Value
    * @Title
    */
    @PostMapping("/returnAllData")
    @Operation(summary = "返回所有信息")
    public Result <List<TraceabilityData>> returnAllData(){
        return Result.success(traceabilityDataService.returnAllData());
    }

}
